﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.Reflection;
using Styx.Common;
using Styx.Plugins;



namespace PetFighterBot
{
    public partial class SettingsForm : Form
    {
        public SettingsForm()
        {
            InitializeComponent();
        }

        PokehbuddygApi _PokehbuddygApi = new PokehbuddygApi();
        LogicCreatorApi _LogicCreatorApi = new LogicCreatorApi();
        BBSettings _BBSettings = new BBSettings(Application.StartupPath + "\\Plugins\\Pokehbuddy\\Pokehbuddy.xml");

        private void SettingsForm_Load(object sender, EventArgs e)
        {
            picBox_Logo.Image = Image.FromFile(Application.StartupPath + @"\Bots\PetFighter\Includes\Forms\header.jpg");
            lb_Version.Text = "v" + PetFighter._Version.ToString();

            chb_autoRevival.Checked = PetFighterSettings.Instance.autoRevive;
            chb_BattlePvP.Checked = _BBSettings.DoPVP;
            chb_BattleWild.Checked = PetFighterSettings.Instance.PetBattle_Wild;
            chb_LevelMode.Checked = PetFighterSettings.Instance.LevelMode;
            chb_needCatch.Checked = PetFighterSettings.Instance.TrapIfNeed;
            chb_StableMaster.Checked = PetFighterSettings.Instance.useStablemaster;
            chb_UpdateCheck.Checked = PetFighterSettings.Instance.CheckForUpdates;
            lb_lastUpdate.Text = "last check: " + DateTime.FromBinary(PetFighterSettings.Instance.LastUpdateCheck);
            nUd_actionAfter.Value = PetFighterSettings.Instance.WaitTime;
            nUd_giveUpAt.Value = PetFighterSettings.Instance.GiveUpAt;
            nUd_startPvPslot.Value = PetFighterSettings.Instance.PvPStartPetSlotID;

            if (!_LogicCreatorApi.HasLogicCreator())
                btn_LogicCreator.BackColor = Color.DarkRed;
            if (!_PokehbuddygApi.HasPokehbuddy())
                btn_Pokehbuddy.BackColor = Color.DarkRed;
        }

        private void SettingsForm_FormClosing(object sender, FormClosingEventArgs e)
        {
            PetFighterSettings.Instance.autoRevive = chb_autoRevival.Checked;
            _BBSettings.DoPVP = chb_BattlePvP.Checked;
            PetFighterSettings.Instance.PetBattle_Wild = chb_BattleWild.Checked;
            PetFighterSettings.Instance.LevelMode = chb_LevelMode.Checked;
            PetFighterSettings.Instance.TrapIfNeed = chb_needCatch.Checked;
            PetFighterSettings.Instance.useStablemaster = chb_StableMaster.Checked;
            PetFighterSettings.Instance.CheckForUpdates = chb_UpdateCheck.Checked;
            PetFighterSettings.Instance.WaitTime = (int)nUd_actionAfter.Value;
            PetFighterSettings.Instance.GiveUpAt = (int)nUd_giveUpAt.Value;
            PetFighterSettings.Instance.PvPStartPetSlotID = (int)nUd_startPvPslot.Value;

            PetFighterSettings.Instance.Save();
            _BBSettings.Save();
        }

        private void btn_LogicCreator_Click(object sender, EventArgs e)
        {
            if (_LogicCreatorApi.HasLogicCreator())
                _LogicCreatorApi.OnButtonPress();
            else
            {
                Logging.Write(System.Windows.Media.Colors.Firebrick, "Please install the Plugin [LogicCreator for Pokébuddy] \n visit:\n http://www.thebuddyforum.com/honorbuddy-forum/plugins/uncataloged/96589-petbattle-plugin-logiccreator-pok-buddy.html");
                MessageBox.Show("Please install the Plugin [LogicCreator for Pokébuddy]", "error", MessageBoxButtons.OK, MessageBoxIcon.Error);
            }
        }

        private void btn_Pokehbuddy_Click(object sender, EventArgs e)
        {
            _BBSettings.DoPVP = chb_BattlePvP.Checked;
            _BBSettings.Save();


            if (_PokehbuddygApi.HasPokehbuddy())
                _PokehbuddygApi.OnButtonPress();
            else
            {
                Logging.Write(System.Windows.Media.Colors.Firebrick, "Please install the Plugin [Pokébuddy] \n visit:\n http://www.thebuddyforum.com/honorbuddy-forum/plugins/uncataloged/81355-plugin-pok-buddy-gotto-kill-em-all.html");
                MessageBox.Show("Please install the Plugin [Pokébuddy]", "error", MessageBoxButtons.OK, MessageBoxIcon.Error);
            }
        }
    }
}
